package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.service.UserService;
import com.qf.util.ResponseUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/25 16:55
 */
@RequestMapping("/user")
@RestController
@CrossOrigin("*")
public class UserController {
    @Autowired
   private UserService service;
    @RequestMapping("/list")
    public  Object list( String username,
                         String mobile,
                        @RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10") Integer limit,
                        @RequestParam(defaultValue = "add_time") String sort,
                        @RequestParam(defaultValue = "desc") String desc){

        IPage<DtsUser> userAll = service.findUserAll(username, mobile, page, limit, sort, desc);

        List<DtsUser> records = userAll.getRecords();
        long total = userAll.getTotal();
        HashMap<String,Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", records);

        return ResponseUtil.ok(data);
    }
}
